package chapter02

object Test22_List3 {
  def main(args: Array[String]): Unit = {
    //先读取文件
    val strings = {
      scala.io.Source.fromFile("2020phonelocation.txt").getLines()
    }.toList
//    val strings1 = for (i <- strings) yield i
//    val list = strings1.toList
//    println(list)
    println("请输入电话号码：")
    val phone = scala.io.StdIn.readLine()
    if(phone.length!=11){
      println("电话号码长度不正确")
    }else{
      for(i<-strings){
        if(i.contains(phone.substring(0,7))){
          println(i)
        }
      }
      strings.foreach(i=>{if(i.contains(phone.substring(0,7))) println(i)})
      println(strings.filter(i=>{i.contains(phone.substring(0,7))}))
      println(strings.filter(_.contains(phone.substring(0,7))))
    }
  }
}
